<template>
  <page-header-wrapper>
    <application-search @search="handleSearch" @reset="handleReset"> </application-search>
    <a-card :bordered="false">
      <s-table
        ref="table"
        size="default"
        rowKey="ID"
        :columns="columns"
        :data="loadData"
        :pagination="{ showTotal: (total) => `共 ${total} 条` }"
        :scroll="{ x: 1800 }"
      >
        <span slot="index" slot-scope="text, record, index">{{ index + 1 }} </span>
        <div slot="action" slot-scope="text, record">
          <y-button
            type="link"
            @click="handleChangeForm(record.ID, record.IDCard, record.ApplyNo, record.YdReason, false)"
            >查看</y-button
          >
          <y-button
            type="link"
            @click="handleChangeForm(record.ID, record.IDCard, record.ApplyNo, record.YdReason, true)"
            >修改</y-button
          >
        </div>
      </s-table>
    </a-card>
    <data-change-form :visible.sync="visibleForm" :data.sync="editData" :isForm="changeForm"></data-change-form>
  </page-header-wrapper>
</template>

<script>
import { STable, Ellipsis, applicationSearch } from '@/components'
import { getProposerList } from '@/api/common'
import dataChangeForm from '../../dataChange/dataChangeForm.vue'
export default {
  name: 'cityComplexInquireList',
  components: {
    STable,
    Ellipsis,
    applicationSearch,
    dataChangeForm,
  },
  computed: {
    textColor() {
      return function (text) {
        const classMap = new Map([
          ['符合', 'text-success'],
          ['不符合', 'text-error'],
          ['未审批', 'text-warning'],
        ])
        return classMap.get(text)
      }
    },
  },
  data() {
    return {
      visibleForm: false,
      changeForm: false,
      editData: {},
      queryParam: {
        UserID: this.$store.getters.userid,
        Mode: 'BASjDataYd',
        strContent: {},
      },
      columns: [
        {
          title: '序号',
          align: 'center',
          width: '80px',
          scopedSlots: { customRender: 'index' },
        },
        {
          title: '申请人',
          align: 'center',
          dataIndex: 'Proposer',
        },
        {
          title: '身份证号',
          align: 'center',
          dataIndex: 'IDCard',
        },
        {
          title: '保障类型',
          align: 'center',
          dataIndex: 'ApplyClass',
        },
        {
          title: '补贴方式',
          align: 'center',
          dataIndex: 'CityVfyAssign',
        },
        {
          title: '区县',
          align: 'center',
          dataIndex: 'RegionName',
          customRender: (text) => (
            <ellipsis length={16} tooltip>
              {text || '/'}
            </ellipsis>
          ),
        },
        {
          title: '街道/办事处',
          align: 'center',
          dataIndex: 'TownshipName',
          customRender: (text) => (
            <ellipsis length={16} tooltip>
              {text || '/'}
            </ellipsis>
          ),
        },
        {
          title: '核定保障人数',
          align: 'center',
          dataIndex: 'CityVfyNumber',
        },
        {
          title: '人均面积',
          align: 'center',
          dataIndex: 'CityVfyAreaPer',
          customRender: (text) => text || '/',
        },
        {
          title: '保障金额',
          align: 'center',
          dataIndex: 'SMoney',
          customRender: (text) => text || '暂无保障金额',
        },
        {
          title: '审批结果',
          align: 'center',
          dataIndex: 'CityRfyResult',
          customRender: (text) => <span class={this.textColor(text || '未审批')}>{text || '未审批'}</span>,
        },
        {
          title: '异动类型',
          align: 'center',
          dataIndex: 'AlterType',
          customRender: (text) => text || '/',
        },
        {
          title: '异动原因',
          align: 'center',
          dataIndex: 'AlterInfo',
          customRender: (text) => (
            <ellipsis class="text-warning" length={20} tooltip>
              {text || '/'}
            </ellipsis>
          ),
        },
        {
          title: '操作',
          align: 'center',
          width: 120,
          fixed: 'right',
          scopedSlots: { customRender: 'action' },
        },
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        return getProposerList(requestParameters).then((res) => {
          return res
        })
      },
    }
  },
  methods: {
    handleSearch(values) {
      this.queryParam.strContent = values
      this.$refs.table.refresh(true)
    },
    handleReset() {
      this.queryParam.strContent = {}
      this.typeSelect = ''
      this.$refs.table.refresh(true)
    },
    handleChangeForm(id, IDCard, YdReason, ApplyNo, isForm) {
      // this.visibleForm = true
      // this.changeForm = isForm
      // this.editData = record
      localStorage.setItem('browserCache', JSON.stringify({ id, IDCard, YdReason, ApplyNo, isForm }))
      this.$router.push({
        name: 'CityLevelDataAnomalies',
        params: {
          id,
          IDCard,
          YdReason,
          ApplyNo,
          isForm: isForm,
        },
      })
    },
    handleFormChange() {
      this.$refs.table.refresh()
    },
    handleInvalidCancel() {
      this.invalidForm.resetFields()
      this.editData = {}
      this.visibleInvalid = false
    },
  },
}
</script>
<style lang="less" scoped></style>
